home *** CD-ROM | disk | FTP | other *** search
- Path: news.ycc.yale.edu!ackerber
- From: ackerber@econ.yale.edu (Daniel Ackerberg)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Help!! Allocating Memory
- Date: 17 Apr 1996 19:53:46 GMT
- Organization: Yale University
- Message-ID: <4l3i8a$6lu@news.ycc.yale.edu>
- NNTP-Posting-Host: dido.econ.yale.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi. I am a novice trying to run a C program with a large (~10 Meg) array
- on a Sparc 20 running SunOS and with 64 Meg of RAM.
-
- The program essential calls a short (~1.5 second) function that runs
- through and performs some operations on the 10 Meg array.
-
- My problem is that on starting the program, the "function" takes about
- 1.5 seconds for each evaluation. This continues for about 5-10 minutes.
- Then, suddenly, after what seems to be a random amount of time or number
- of evaluations, the function starts to take about 2.7 seconds per evaluation.
-
- The following is the simplest program I have that exhibits this "bug":
-
-
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- #define MEM 10 /* How many megs the array should be */
-
- void main()
- {
- double *x;
- long int sz,i,k,c;
-
- sz=MEM*1024000/8;
-
- if ((x = (double *) malloc (sizeof(double) * sz)) == NULL) {
- printf("Memory Error.\n");
- exit(1);
- }
-
- /* Loop over function Evaluations */
-
- for(k=0;k<100000;k++)
- {
- c=clock();
- for(i=0;i<sz;i++) x[i]=0.99;
- for(i=0;i<sz;i++) x[i]=exp(x[i]*x[i]);
- printf("Time: %f\n",((float)(clock()-c))*1e-6); fflush(stdout);
- }
-
- }
-
-
- Note that in this simple program, the function does the EXACT same thing
- each time, so I do not understand why it starts off taking 1.5 seconds
- and then switches to almost double the time. I think it must have something
- to do with the large size of the array and swapping , although I don't
- understand why it would be swapping. Also when I use "top" to watch what
- is going on, the program starts with about 10 Meg resident in memory.
- Then around the time it slows down, I occasionally see the resident memory
- go down by 8 K. Is this small amount of memory being swapped and
- drastically slowing down the program? If so , is there any way to prevent
- this from happening? I've showed this program to my system administrators
- and they don't seem to know what is going on. Any help would be
- tremendously appreciated.
-
- Thank you , Dan.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A
-
-